﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MvcWiki.Model
{
    public class WikiPageRevision
    {
        public DateTime Created { get; protected set; }

        public virtual string Content { get; protected set; }

        public WikiPageRevision(DateTime created, string content)
        {
            this.Created = created;
            this.Content = content;
        }

        #region Object

        public override int GetHashCode()
        {
            return Created.GetHashCode();
        }

        public override bool Equals(object obj)
        {
            if (object.ReferenceEquals(obj, null))
            {
                return false;
            }

            if (this.GetType() != obj.GetType())
            {
                return false;
            }

            var revision = obj as WikiPageRevision;

            var created1 = new DateTime(this.Created.Year, this.Created.Month, this.Created.Day, this.Created.Hour, this.Created.Minute, this.Created.Second, this.Created.Kind);
            var created2 = new DateTime(revision.Created.Year, revision.Created.Month, revision.Created.Day, revision.Created.Hour, revision.Created.Minute, revision.Created.Second, revision.Created.Kind);

            return created1 == created2 && this.Content == revision.Content;
        }

        public static bool operator ==(WikiPageRevision wikiPageRevision1, WikiPageRevision wikiPageRevision2)
        {
            if (object.ReferenceEquals(wikiPageRevision1, null) && object.ReferenceEquals(wikiPageRevision2, null))
            {
                return true;
            }

            if (object.ReferenceEquals(wikiPageRevision1, null) || object.ReferenceEquals(wikiPageRevision2, null))
            {
                return false;
            }

            return wikiPageRevision1.Equals(wikiPageRevision2);
        }

        public static bool operator !=(WikiPageRevision wikiPageRevision1, WikiPageRevision wikiPageRevision2)
        {
            return !(wikiPageRevision1 == wikiPageRevision2);
        }

        #endregion
    }
}
